$.extend({
    /*
    * 整合 百度上传插件
    */
    WebUploader: function (options) {


        //默认注册双向参数集合
        if (!options.hasOwnProperty("uploader"))
            options.uploader = {};
        if (!options.hasOwnProperty("online"))
            options.online = {};

        //设置 上传控制中转头
        if (!options.hasOwnProperty("server")) {
            options.server = "写你的webapi地址";
            options.uploader.server = "写你的webapi地址";
        }

        //默认开启 所有功能
        if (!options.hasOwnProperty("easyopen"))
            options.easyopen = { uploader: true, online: false };

        //如果不打开所有功能，不执行任何结构跟逻辑
        if (!options.easyopen && !options.easyopen)
            return;

        //默认全局是否加前缀名
        if (options.hasOwnProperty("imgPrefix")) {
            options.uploader.imgPrefix = options.imgPrefix;
            options.online.imgPrefix = options.imgPrefix;
        }
        //关闭后是否销毁结构 默认否
        if (!options.hasOwnProperty("destroy")) {
            options.destroy = true;
        }
        options.uploader.destroy = options.destroy;
        /*
         * 创建html结构
         * web-uploader-bg 背景
         * web-uploader-body-main
         */
        function CreateHtml() {
            var _Html = '<div class="web-uploader-bg">' +
                '        <div class="web-uploader-body-main">' +
                '            <div class="web-uploader" onselectstart="return false">' +
                '                <div class="web-uploader-body">' +
                '                    <div class="web-uploader-left">' +
                '                        <div class="web-uploader-title bg-success">' +
                '                            <!--<span class="web-uploader-title-text">目录</span>-->' +
                '                            <div class="web-uploader-search ">' +
                '                                <div class="uploader-dis online-show">' +
                '                                    <select id="wu-search-year" class="form-control search-select">' +
                '                                    </select>' +
                '                                </div>' +
                '                                <div class="uploader-dis online-show">' +
                '                                    <select id="wu-search-month" class="form-control search-select">' +
                '                                        <option value="0">不选</option>' +
                '                                        <option value="01">1</option>' +
                '                                        <option value="02">2</option>' +
                '                                        <option value="03">3</option>' +
                '                                        <option value="04">4</option>' +
                '                                        <option value="05">5</option>' +
                '                                        <option value="06">6</option>' +
                '                                        <option value="07">7</option>' +
                '                                        <option value="08">8</option>' +
                '                                        <option value="09">9</option>' +
                '                                        <option value="10">10</option>' +
                '                                        <option value="11">11</option>' +
                '                                        <option value="12">12</option>' +
                '                                    </select>' +
                '                                </div>' +
                '                            </div>' +
                '                        </div>' +
                '                        <div class="web-uploader-online-dire">' +
                '                            <div class="web-uploader-dire uploader-dis uploader-show">' +
                '                                <p>你可以使用截图工具(如QQ截图工具)粘贴到右边上传列表。</p>' +
                '                                <p>也可以选中文件拖动到上传列表</p>' +
                '                                <p class="web-uploader-tip">' +
                '                                    本次上传限制文件' +
                '                                    <br />' +
                '                                    <span id="web-uploader-astrict-tip">0</span>' +
                '                                </p>' +
                '                                <p class="web-uploader-tip">' +
                '                                    限制单个文件大小<br />' +
                '                                    <span id="web-uploader-single-tip">0kb</span>' +
                '                                </p>' +
                '                            </div>' +
                '                            <ul id="web-uploader-online-dire-ul" class="web-uploader-online-dire-ul uploader-dis online-show"></ul>' +
                '                        </div>' +
                '                    </div>' +
                '                    <div class="web-uploader-right">' +
                '                        <div class="web-uploader-title w-u-t-r">' +
                '                            <ul id="w-u-nav" class="w-u-nav">' +
                '                                <li class="active"><a href="javascript:;" data-sel="uploader">上传文件</a></li>' +
                '                                <li><a href="javascript:;" data-sel="online">在线管理</a></li>' +
                '                            </ul>' +
                '                            <a class="web-uploader-colse" href="javascript:;" title="关闭">X</a>' +
                '                        </div>' +
                '                        <div class="web-uploader-img-body">' +
                '                            <div id="web-uploader-img-main" class="web-uploader-img-main uploader-dis uploader-show">' +
                '                                <ul id="web-uploader-img-ul" class="web-uploader-img-ul"></ul>' +
                '                            </div>' +
                '                            <div id="web-online-img-main" class="web-online-img-main uploader-dis online-show">' +
                '                            </div>' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '                <div class="web-uploader-progress">' +
                '                    <div class="progress">' +
                '                        <div class="progress-bar progress-bar-striped active" style="width: 100%">' +
                '                            100%' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '                <div class="web-uploader-bottom">' +
                '                    <div class="web-uploader-bottom-left">' +
                '                        <p class="web-uploader-msg uploader-dis uploader-show">' +
                '                            <span>文件数量<i id="w-u-file-count"></i> /</span>' +
                '                            <span>成功<i id="w-u-filesuccee-count">0</i> /</span>' +
                '                            <span>失败<i id="w-u-filefail-count">0</i></span>' +
                '                        </p>' +
                '                        <p class="web-uploader-online-msg uploader-dis online-show">' +
                '                            <span>当前选中<i id="w-u-file-online-count">0</i> /</span>' +
                '                            <span>允许选中<i id="w-u-file-online-iscount">0</i></span>' +
                '                        </p>' +
                '                    </div>' +
                '                    <div>' +
                '                        <div class="web-uploader-btns uploader-dis uploader-show">' +
                '                            <input id="btn-retry-upload" type="button" value="重试上传" class="btn btn-danger " />' +
                '                            <a id="btn-add-img" class="btn btn-default web-uploader-addimg">选择文件</a>' +
                '                            <input id="btn-start-upload" type="button" value="开始上传" class="btn btn-success" />' +
                '                        </div>' +
                '                        <div class="web-uploader-online-btns uploader-dis online-show">' +
                '                            <input type="button" id="web-uploader-selfiles" class="btn btn-success" value="确定选择" />' +
                '                            <input type="button" id="web-uploader-delfiles" class="btn btn-danger" value="删除选中文件" />' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '                <div class="web-uploader-layre"></div>' +
                '            </div>' +
                '            <div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">' +
                '                <div class="pswp__bg"></div>' +
                '                <div class="pswp__scroll-wrap">' +
                '                    <div class="pswp__container">' +
                '                        <div class="pswp__item"></div>' +
                '                        <div class="pswp__item"></div>' +
                '                        <div class="pswp__item"></div>' +
                '                    </div>' +
                '                    <div class="pswp__ui pswp__ui--hidden">' +
                '                        <div class="pswp__top-bar">' +
                '                            <div class="pswp__counter"></div>' +
                '                            <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>' +
                '                            <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>' +
                '                            <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>' +
                '                            <div class="pswp__preloader">' +
                '                                <div class="pswp__preloader__icn">' +
                '                                    <div class="pswp__preloader__cut">' +
                '                                        <div class="pswp__preloader__donut"></div>' +
                '                                    </div>' +
                '                                </div>' +
                '                            </div>' +
                '                        </div>' +
                '                        <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">' +
                '                            <div class="pswp__share-tooltip"></div>' +
                '                        </div>' +
                '                        <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>' +
                '                        <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>' +
                '                        <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>' +
                '                        <div class="pswp__caption">' +
                '                            <div class="pswp__caption__center"></div>' +
                '                        </div>' +
                '                    </div>' +
                '                </div>' +
                '            </div>' +
                '        </div>' +
                '    </div>';
            if ($(".web-uploader-body-main").length <= 0)
                $(document.body).append(_Html);
        }
        //加载html结构
        CreateHtml();

        //开启
        var bg_length = $(".web-uploader-body-main").length;
        if (bg_length > 0) {
            if ($(".web-uploader-body-main").is("visible")) {
                $(".web-uploader-body-main").hide();
                $(".web-uploader-bg").hide();
            } else {
                $(".web-uploader-body-main").fadeIn(200);
                $(".web-uploader-bg").fadeIn(200);
            }
        } else {
            $(".web-uploader-body-main,").fadeIn(200);
            $(".web-uploader-bg").fadeIn(200);
        }


        //拖动
        $(".web-uploader").draggabilly({ handle: ".w-u-t-r", containment: '.web-uploader-bg' });

        //ajax
        var $webuploaderAjax = function (d, v, succFu, erfu) {
            if (typeof (errorFu) == "undefined") { errorFu = function () { }; }
            $.ajax({
                type: "POST",
                url: options.server,
                beforeSend: function () { },
                data: { "webuploaderidentity": d, "webuploaderValue": v },
                dataType: 'json',
                success: succFu,
                error: errorFu,
                complete: function (XHR, TS) {
                    XHR = null;
                }
            });
        }


        /*
         * 提示框
         */
        var uploaderLayre = function (opts) {
            if (!opts.hasOwnProperty("text"))
                opts.text = "";
            //打开
            if (opts.show) {
                $(".web-uploader-layre").html(opts.text).fadeIn(300, function () {
                    setTimeout(function () {
                        $(".web-uploader-layre").fadeOut(300);
                    }, 3000);
                });
            } else if (!opts.show) {
                $(".web-uploader-layre").fadeOut();
            }
        }

        /*
         * 上传插件枚举
         */
        var $uploaderEnum =
            {
                Q_EXCEED_NUM_LIMIT: "添加的文件数量已超出最大限制数量",
                Q_EXCEED_SIZE_LIMIT: "添加的文件过大了",
                Q_TYPE_DENIED: "不支持该类型文件加入上传列表",
                F_EXCEED_SIZE: "添加的文件过大了"
            }


        var icofig = {
            url: "../img/uk/",
            ico: [
                { ec: ["txt"], img: "s-txt.png" },
                { ec: ["rar", "zip", "iso"], img: "s-rar.png" },
                { ec: ["wav", "wma", "ogg", "ape", "acc"], img: "s-audio.png" },
                { ec: ["avi", "rmvb", "rm", "flash", "mp4", "3gp"], img: "s-video.png" },
                { ec: ["exe"], img: "s-exe.png" },
                { ec: ["mp3"], img: "s-mp3.png" },
                { ec: ["ppt", "pptx"], img: "s-ppt.png" },
                { ec: ["doc", "docx"], img: "s-word.png" }
            ]
        };

        var icourl = function (fielex) {
            var s = "s-uk.png";
            $.each(icofig.ico, function (k, v) {
                for (var i = 0; i < v.ec.length; i++) {
                    if (fielex.toLocaleLowerCase() == v.ec[i]) {
                        s = v.img;
                    }
                }
            })
            return icofig.url + s;
        }

        /*
        * 扩展方法
        */
        var existAudio = function (fileExt) {
            var a = [
                "bmp", "gif", "jpeg", "png", "svg","ico"];
            for (var i = 0; i < a.length; i++) {
                if (fileExt == a[i]) {
                    return true;
                }
            }
            return false;
        }

        //上传插件
        function $$uploader(options) {

            //属性值保存参数
            this.opts = options;

            //一次性能加载多少文件 默认6张
            if (!opts.hasOwnProperty("fileNumLimit")) {
                opts.fileNumLimit = 6;
            }

            //上传单个文件大小 单位/b 计算 默认1MB
            if (!opts.hasOwnProperty("fileSingleSizeLimit")) {
                opts.fileSingleSizeLimit = (1024 * 1024 * 1024);
            }

            //最大上传并发数量 3
            if (!opts.hasOwnProperty("threads")) {
                opts.threads = 3;
            }

            //判断前缀名 默认不加
            if (!options.hasOwnProperty("imgPrefix")) {
                options.imgPrefix = "";
            }

            if (!opts.hasOwnProperty("accept")) { //过滤文件类型
                opts.accept = {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png,ico',
                    mimeTypes: 'image/*'
                };
            }
            if (!opts.hasOwnProperty("compress")) { //是否压缩图片 默认压缩 false=不压缩
                opts.compress = {};
            }

            if (!options.hasOwnProperty("succee")) { //上传图片成功触发回调函数
                options.succee = function () { };
            }

            //判断函数是否已经存在
            if (typeof (eval($uploader)) == "function") {
                return true;
            }

            //设置上传限制提示
            $("#web-uploader-astrict-tip").text(opts.fileNumLimit);
            $("#web-uploader-single-tip").text(WebUploader.Base.formatSize(opts.fileSingleSizeLimit));

            //合并参数
            //默认参数
            var uploadr_param = $.extend({
                pick: { id: "#btn-add-img", innerHTML: "选择文件", multiple: true },
                disableGlobalDnd: true, duplicate: true,
                dnd: "#web-uploader-img-ul",// --指定拖动元素
                paste: $(document.body),
                server: opts.server,
                fileVal: "webuploaderfile", //文件域
                formData: { "webuploaderidentity": "upload" },
                thumb: { //缩图 无需重写
                    width: 126,
                    height: 80,
                    quality: 100,
                    allowMagnify: false
                }
            }, this.opts);
            //创建上传实例
            var $uploader = WebUploader.create(uploadr_param);

            //当文件被加入队列之前触发，此事件的handler返回值为false，则此文件不会被添加进入队列。
            $uploader.on("beforeFileQueued", function (file) {
                $uploader.on('error', function (handler) {
                    var rs = eval("$uploaderEnum." + handler);
                    uploaderLayre({ show: true, text: rs });
                })
            })

            //当文件被加入队列以后触发
            $uploader.on('fileQueued', function (file) {
                var size = WebUploader.Base.formatSize(file.size, 0, ['B', 'KB', 'MB']);
                var d = size.match(/[a-z|A-Z]+/);
                var v = size.replace(d, "");
                var _Html = '<li id=' + file.id + '>' +
                    '<div class="web-uploader-img-list">' +
                    '        <div class="web-uploader-img-top">' +
                    '            <a class="web-uploader-img-singledel" title="移除该项"><span>X</span></a>' +
                    '        </div>';
                $uploader.makeThumb(file, function (error, ret) {
                    if (error) {
                        console.log(error);
                        _Html += ' <img src="' + icourl(file.ext) + '" />';
                    } else {
                        _Html += ' <img src="' + ret + '" />';
                    }
                    _Html += '<div class="web-uploader-img-message"></div>' +
                        '    </div>' +
                        '    <div class="web-uploader-img-name">' + file.name + '</div>' +
                        '    <div class="web-uploader-img-progress">' +
                        '    <div class="progress">' +
                        '        <div class="progress-bar progress-bar-success progress-bar-striped active" style="width: 0%;" >' +
                        '            0%' +
                        '        </div>' +
                        '    </div>' +
                        '</div>' +
                        '<div class="web-uploader-img-size"><span>' + v + '</span><i>' + d + '</i></div>' +
                        '</li>';
                    $(".web-uploader-img-ul").append(_Html);
                    $("#w-u-file-count").text(
                        $(".web-uploader-img-ul > li").length);
                });
            })


            //当文件被移除队列后触发 删除实时显示文件效果图
            $uploader.on("fileDequeued", function (file) {
                $("#" + file.id).remove();
                //删除大小
                $("#w-u-file-count").text(
                    $(".web-uploader-img-ul > li").length);
            })



            //上传进度条
            $uploader.on("uploadProgress", function (file, Number) {
                $("#" + file.id).children("div[class='web-uploader-img-progress']").
                    children().children().
                    css({ width: parseInt(Number * 100) + "%" }).text(parseInt(Number * 100) + "%");
                uploaderLayre({ show: false });
            })


            //上传成功
            $uploader.on("uploadSuccess", function (file, response) {
                //如果加前缀名 重新格式json数组
                var j = JSON.parse(response._raw);
                if (options.imgPrefix != "") {
                    j.url = options.imgPrefix + j.url;
                }
                options.succee(j);
                $("#btn-retry-upload").css({ display: "none" });
                if (j.error > 0) {
                    $("#" + file.id).children("div[class='web-uploader-img-list']").
                        children("div[class='web-uploader-img-message']").
                        html("类型错误").slideDown();
                    $("#" + file.id).children("div[class='web-uploader-img-progress']").
                        children().children().
                        css({ width: "0%" });
                    return;
                }

                //关闭提示栏
                $("#" + file.id).children("div[class='web-uploader-img-list']").
                    children("div[class='web-uploader-img-message']").
                    html("").slideUp();
            })

            //上传错误 $("#btn-retry-upload").css({ display: "none" });
            $uploader.on("uploadError", function (file, response) {
                uploaderLayre({ show: true, text: '有上传失败的文件,请尝试重新上传' });
                $("#" + file.id).children("div[class='web-uploader-img-progress']").
                    children().children().
                    css({ width: "0%" });

                //打开提示栏
                $("#" + file.id).children("div[class='web-uploader-img-list']").
                    children("div[class='web-uploader-img-message']").
                    html("上传失败").slideDown();
                $("#btn-retry-upload").css({ display: "inline-block" });
            })

            //不管成功失败都会调用
            $uploader.on("uploadComplete", function (file) {
                $("#w-u-filesuccee-count").text($uploader.getStats().successNum);
                $("#w-u-filefail-count").text($uploader.getStats().uploadFailNum);
            })

            //上传图片
            $("#btn-start-upload").unbind("click");
            $("#btn-start-upload").on('click', function () {
                if ($("#web-uploader-img-ul > li").length <= 0) {
                    uploaderLayre({ show: true, text: '没文件可上传' });
                    return;
                }
                $uploader.upload();
            })

            //绑定鼠标 .web-uploader-img-ul > li > div
            $(".web-uploader-img-ul").on("mouseenter", " > li", function () {
                if (!$(this).children("div[class='web-uploader-img-top']").is(":animated")) {
                    $(this).children("div[class='web-uploader-img-list']")
                        .children("div[class='web-uploader-img-top']")
                        .slideDown();
                }
            }).on("mouseleave", " > li", function () {
                $(this).children("div[class='web-uploader-img-list']")
                    .children("div[class='web-uploader-img-top']")
                    .hide();
            })

            //移除文件事件
            $(document.body)
                .off("click", ".web-uploader-img-singledel")
                .on("click", ".web-uploader-img-singledel", function () {
                    var id = $(this).parents("li").attr("id");
                    $uploader.removeFile(id, true);
                })


            //关闭 重置上传所有文件
            $(".web-uploader-colse").unbind("click");
            $(".web-uploader-colse").on("click", function () {
                $uploader.reset(); $uploader.destroy();
                $("#web-uploader-img-ul > li").remove();
                $("#w-u-file-count,#w-u-filesuccee-count,#w-u-filefail-count").text(0);
                $(".web-uploader-bg,.web-uploader-body-main").fadeOut(200, function () {
                    if (options.destroy)
                        $(this).remove();
                });
            })

            //重试上传出错 文件
            $("#btn-retry-upload").unbind("click");
            $("#btn-retry-upload").on("click", function () {
                $uploader.retry();
            })
        }

        //在线管理文件
        var $$uploaderOnline = function (options) {
            //属性保存参数值
            this.opts = options;

            //参数初始化 判断

            //默认允许选中
            if (!opts.hasOwnProperty("select"))
                opts.select = true;

            /*
             * 强制选中 必须选中多少文件才能回调
             * 默认不强制选择
             * 强制选中跟 selnum值挂钩，如果selnum值 <=0
             * 该限制无效
            */
            if (!opts.hasOwnProperty("compel"))
                opts.compel = false;

            //默认无限制选中
            if (!opts.hasOwnProperty("selnum"))
                opts.select = 0;

            //给初始属性
            if (!options.hasOwnProperty("succeeSel"))
                options.succeeSel = function () { };

            //默认打开 openPhoto 图片查看器
            if (!opts.hasOwnProperty("openPhoto"))
                opts.openPhoto = true;

            //判断前缀名 默认不加
            if (!opts.hasOwnProperty("imgPrefix"))
                opts.openPhoto = "";

            //设置提示文本
            if (opts.selnum == 0) {
                $("#w-u-file-online-iscount").text("无限制");
            } else {
                $("#w-u-file-online-iscount").text(opts.selnum);
            }


            //如果不打开图片查看器，移除结构
            if (!opts.openPhoto) {
                $(".pswp").remove();
            }

            /* 查询 用户自己拥有的文件夹
             * 追加到下拉列表
             * 加载时候需要加载
             */
            function onlineDireYear() {
                return;
                $webuploaderAjax("DireYear", "", function (d) {
                    var _Html = '';
                    if (d == null || d == "") {
                        _Html += '<option value="0000">暂无</option>';
                        $("#wu-search-year").append(_Html);
                        return false;
                    }
                    $("#wu-search-year > option").remove();
                    for (var i = 0; i < d.length; i++) {
                        _Html += '<option value="' + d[i] + '">' + d[i] + '</option>';
                    }
                    $("#wu-search-year").append(_Html);

                    //默认选中最大的
                    $("#wu-search-year > option[value='" + Math.max.apply({}, d) + "']")
                        .prop("selected", true);
                });
            }

            /* 查询自己的所有文件名
             * 第一次 加载会执行该方法
             */
            function onlineQueryDire(v) {
                $webuploaderAjax("getallDireName", v, function (d) {
                    $("#web-uploader-online-dire-ul > li").remove();
                    var _Html = "";
                    if (d == null || d == "") {
                        _Html += '<li>';
                        _Html += '<i></i>' +
                            '<span>没找到文件</span></li>';
                        $("#web-uploader-online-dire-ul").append(_Html);
                        return false;
                    }
                    for (var i = 0; i < d.length; i++) {
                        _Html += '<li date-file="' + d[i] + '">';
                        _Html += '<i></i>' +
                            '<span>' + d[i] + '</span></li>';
                    }
                    $("#web-uploader-online-dire-ul").append(_Html);
                })
            }


            /*
             * 点击目录文件
             * 点击左边的目录 某年某月末日 加载对应图片
            */
            function onlineLoadFile(v, n) {
                //判断是否已经追加到右边内容区域
                var w_o_t = $(".web-online-title[data-isfile='" + v + "']");
                if ($(w_o_t).length > 0) {
                    $("#web-online-img-main").animate(
                        { scrollTop: $(w_o_t).position().top }, 600);
                    return;
                }
                $webuploaderAjax("queryMyFile", v, function (d) {
                    if (d == null || d == '') {
                        uploaderLayre({ show: true, text: "该文件夹下不存在文件" });
                        return false;
                    }
                    var _Html = '<div class="web-online-grous">';
                    _Html += '<div class="web-online-title" data-isfile=' + v + '>' + n + '</div>';
                    _Html += '<ul class="web-online-img-ul">';
                    $.each(d, function (k, v) {
                        _Html += ' <li data-id="' + v.webUrl + '">' +
                            '    <div class="web-online-img-list">' +
                            '        <div class="web-online-img-top">' +
                            '            <a class="web-online-img-singledel" title="删除"><span>X</span></a>' +
                            '        </div>' +
                            '        <img src="' + v.imgUrl + '" />' +
                            '        <div class="web-online-img-message">查看</div>' +
                            '    </div>' +
                            '    <div class="web-online-img-name">' + v.fileName + '</div>' +
                            '    <span class="online-iocn"></span>' +
                            '</li>';
                    })
                    _Html += '</ul>';
                    _Html += '</div>';
                    $("#web-online-img-main").prepend(_Html);
                })
            }

            /*
             * 请求服务器 删除文件
             *
             */
            function onlineDeleteFile(v) {
                $webuploaderAjax("DeleteMyFile", v, function (d) {
                    if (d == null || d == "") { return false; }
                    $.each(d, function (k, v) {
                        if (v.DelState) {
                            $(".web-online-img-ul >li[class='o-ul-select'][data-id='" + v.ImgUrl + "']")
                                .fadeOut(300, function () {
                                    $(this).remove();
                                    uploaderLayre({ show: true, text: "文件已被永久删除" });
                                })
                        }
                    })
                })
            }

            /*
             * 绑定事件
             * 图片点击 加印选中效果
             * 由选中参数为定义选中上限
            */
            $(document.body).off("click", ".web-online-img-ul > li")
                .on("click", ".web-online-img-ul > li", function () {
                    //不允许选中
                    if (!opts.select) {
                        $("#w-u-file-online-iscount").text("不可选");
                        return;
                    }
                    if ($(this).hasClass("o-ul-select")) {
                        $(this).removeClass("o-ul-select");
                        //统计选中数量
                        $("#w-u-file-online-count").text(
                            $(".web-online-img-ul > li[class='o-ul-select']").length
                        );
                    } else {
                        if (opts.selnum != 0) {
                            var count = $(".web-online-img-ul > li[class='o-ul-select']").length;
                            if (count >= opts.selnum) {
                                $(".web-online-img-ul > li[class='o-ul-select']").last()
                                    .removeClass("o-ul-select");
                            }
                        }
                        $(this).addClass("o-ul-select");
                        //统计选中数量
                        $("#w-u-file-online-count").text(
                            $(".web-online-img-ul > li[class='o-ul-select']").length
                        );

                    }
                })

            /*
             * web-online-img-ul
             * 绑定鼠标穿入事件 用于启动查看图片查看器
             */
            $(document.body).off("mouseenter", ".web-online-img-ul > li")
                .on("mouseenter", ".web-online-img-ul > li", function () {

                    //不打开图片查看器
                    if (!opts.openPhoto) { return; }
                    $(this).children("div[class='web-online-img-list']")
                        .children("div[class='web-online-img-message']").slideDown();
                })
                .off("mouseleave", ".web-online-img-ul > li")
                .on("mouseleave", ".web-online-img-ul > li", function () {
                    //不打开图片查看器
                    if (!opts.openPhoto) { return; }
                    $(this).children("div[class='web-online-img-list']")
                        .children("div[class='web-online-img-message']").hide();
                })

            /*
             * web-online-img-message
             * 启动图片查看器
             */
            $(document.body)
                .off("click", ".web-online-img-message")
                .on("click", ".web-online-img-message", function (e) {
                    //不打开图片查看器
                    if (!opts.openPhoto) { return; }
                    //实例图片查看器
                    e.stopPropagation();
                    var pswpElement = document.querySelectorAll('.pswp')[0];
                    var s = $(".web-online-img-ul > li > div[class='web-online-img-list'] > img");
                    var t_index = $(this).prev().attr("src");
                    var items = [];
                    $.each(s, function (i) {
                        items[i] = {
                            src: $(this).attr("src"),
                            w: 1200,
                            h: 768
                        };
                        if (t_index == $(this).attr("src"))
                            t_index = i;
                    })
                    // 设置默认打开图片索引
                    var options = {
                        index: t_index,
                        pinchtoclose: true,
                        mouseused: true
                    };
                    // 实例图片查看器
                    var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
                    gallery.init();
                })

            /*
             * 点击左边 目录 加载图片到 右边
             */
            $(document.body)
                .off("click", "#web-uploader-online-dire-ul > li")
                .on("click", "#web-uploader-online-dire-ul > li", function () {
                    $("#web-uploader-online-dire-ul > li").removeClass("active");
                    var this_file = $(this).attr("date-file");
                    var this_span = $(this).children("span").text().trim();
                    $(this).addClass("active");
                    onlineLoadFile(this_file, this_span);
                })


            /*
              * 年下拉列表选择
             */
            $("#wu-search-year").on("change", function () {
                onlineQueryDire($(this).val());
            })

            /*
              * 月下拉列表选择
             */
            $("#wu-search-month").on("change", function () {
                var year = $("#wu-search-year").val();
                var this_v = $(this).val()
                if (this_v == "0") {
                    year = year
                } else {
                    year = year + '-' + this_v;
                }
                onlineQueryDire(year);
            })

            /*
              * 删除选中的文件
              * 组装成JSON字符串后台处理
             */
            $("#web-uploader-delfiles").on("click", function () {
                var delFile = [];
                $.each($(".web-online-img-ul > li[class='o-ul-select']"), function (i) {
                    delFile[i] = { file: $(this).attr("data-id") };
                })
                if (delFile == null || delFile.length <= 0) {
                    uploaderLayre({ show: true, text: "请选择要删除的文件" });
                    return;
                }
                onlineDeleteFile(JSON.stringify(delFile));
            })

            /*
             * 返回选中的文件路径
            */
            $("#web-uploader-selfiles").on("click", function () {
                var selFile = [];
                //判断是否加前缀名
                if (options.imgPrefix != "") {
                    $.each($(".web-online-img-ul > li[class='o-ul-select']"), function (i) {
                        selFile[i] = {
                            url: options.imgPrefix + $(this).children("div[class='web-online-img-list']")
                                .children("img").attr("src")
                        };
                    })
                } else {
                    $.each($(".web-online-img-ul > li[class='o-ul-select']"), function (i) {
                        selFile[i] = {
                            url: $(this).children("div[class='web-online-img-list']")
                                .children("img").attr("src")
                        };
                    })
                }
                //判断是否强制性选中多少图片
                if (options.select && options.compel && options.selnum > 0) {
                    //获取已经选中的图片数量跟设置的数量对比
                    if (selFile.length < options.selnum) {
                        uploaderLayre({
                            show: true,
                            text: "必须选中文件数量:(" + options.selnum + ") 你选中文件:(" + selFile.length + ")"
                        });
                        return;
                    }
                }

                //判断如果没有选中
                if (selFile.length <= 0) {
                    uploaderLayre({ show: true, text: "请选择文件" });
                    return;
                }

                options.succeeSel(selFile);
                $(".web-uploader-bg,.web-uploader-body-main").fadeOut(200, function () {
                    if (options.destroy)
                        $(this).remove();
                });
            })

            //执行默认加载
            //onlineDireYear();
            //onlineQueryDire("");
        }





        /*
         * 查询目录
         * 为切换卡 同步目录设计的
        */
        function QDire(file) {
            $webuploaderAjax("QueryDire", "", function (d) {
                $("#web-uploader-online-dire-ul > li").remove();
                var _Html = "";
                if (d == null || d == "") {
                    _Html += '<li>';
                    _Html += '<i></i>' +
                        '                         <span>没找到文件</span></li>';
                    $("#web-uploader-online-dire-ul").append(_Html);
                    return false;
                }
                for (var i = 0; i < d.length; i++) {
                    _Html += '<li date-file="' + d[i] + '">';
                    _Html += '<i></i>' +
                        '                         <span>' + d[i].split('_')[1].webuploaderDate() + '</span></li>';
                }
                $("#web-uploader-online-dire-ul").append(_Html);
                //恢复上次选中目录
                $("#web-uploader-online-dire-ul > li[date-file='" + file + "']").addClass("active");
            })
        }



        //默认执行
        //判断是否开启那些功能
        if (options.easyopen.uploader) {
            $$uploader(options.uploader);
        } else { //移除组件结构
            $("#w-u-nav > li > a[data-sel='uploader']").remove();
            $(".uploader-show").remove();

            //不开启上传插件功能 绑定关闭层时间
            $(".web-uploader-colse").unbind("click");
            $(".web-uploader-colse").on("click", function () {
                $(".web-uploader-bg,.web-uploader-body-main").fadeOut(200, function () {
                    if (options.destroy)
                        $(this).remove();
                });
            })
        }
        if (options.easyopen.online) {
            $$uploaderOnline(options.online);
        } else { //移除组件结构
            $("#w-u-nav > li > a[data-sel='online']").remove();
            $(".online-show").remove();
        }


        /*
         * 切换栏
         * 1=上传面板 2=在线管理面板
         *  1)当点击在线面板时候重新加载目录栏
         */
        $("#w-u-nav > li > a").click(function () {
            var datasel = $(this).attr("data-sel");
            /* 如果是 在线管理面板
            * 为了保证目录同步 重新查询
            */
            if (datasel == "online" && (!$(this).parent("li").hasClass("active"))) {
                var file = $("#web-uploader-online-dire-ul > li[class='active']")
                    .attr("date-file");
                QDire(file);
            }
            $("#w-u-nav > li").removeClass("active");
            $(this).parent().addClass("active");
            $(".uploader-dis").hide();
            $("." + datasel + "-show").show();
        })
        //给第一个自动选中
        $("#w-u-nav > li").eq(0).addClass("active");

    }
})